﻿
#region Using Statements

using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Freeform;

#endregion


namespace Client
{
    public class MainMenu : World
    {

        #region Members

        public Entity2D Title { get; set; }

        public MenuItem Start, Next, Editor, Options, Exit;

        public Viewport2D View { get; set; }

        private Single VerticalPosition = 25f;
        private Single VerticalOffset = 7f;

        #endregion


        #region Initialisation

        public MainMenu(Freeform.Game Game)
            : base(Game)
        {
            BackgroundColour = new Color(Vector4.Zero);

            View = new Viewport2D(this);
            View.Camera.Size = new Vector2(100, 70);
            View.Depth = 0.5f;

            Title = new Entity2D(this);
            Title.Position = new Vector2(View.Camera.Size.X / 2, 10);
            Title.Size = new Vector2(50, 20);
            new Actor2D_Text(Title, "IsoTurr", Game.Content.Load<SpriteFont>("Fonts/Plain"));
            (Title.Actor as Actor2D_Text).UseNaturalFontSize = true;
            (Title.Actor as Actor2D_Text).NaturalFontScaling = Vector2.One / 4f;
            Title.Actor.Depth = 0.25f;
            Title.Actor.ColourOverlay = Color.CadetBlue;

            MakeItem(ref Start, "Start Game");
            MakeItem(ref Options, "Options");
            MakeItem(ref Exit, "Exit");

            Start.ItemClicked += delegate(MenuItem Item)
            {
                new Test2D(this.Game);
                this.View.IsVisible = false;
            };
            Exit.ItemClicked += delegate(MenuItem Item) { Game.Exit(); };

        }

        #endregion


        private void ItemHighlighted(MenuItem Item)
        {
            Item.TextActor.ColourOverlay = Color.Red;
            Item.TextActor.NaturalFontScaling = Vector2.One / 7f;
        }

        private void ItemLeft(MenuItem Item)
        {
            Item.TextActor.ColourOverlay = Color.White;
            Item.TextActor.NaturalFontScaling = Vector2.One / 9f;
        }

        private void MakeItem(ref MenuItem Item, String Text)
        {
            Item = new MenuItem(this, Text, "Fonts/Plain");
            Item.Position = new Vector2(View.Camera.Size.X / 2, VerticalPosition);
            Item.TextActor.NaturalFontScaling = Vector2.One / 9f;
            Item.TextActor.ColourOverlay = Color.White;
            Item.ItemHighlighted += ItemHighlighted;
            Item.ItemLeft += ItemLeft;
            VerticalPosition += VerticalOffset;
        }
    }
}